package com.chenyuan.http;


import com.chenyuan.datadriven.Functions;
import com.chenyuan.http.EasyHttp;
import com.chenyuan.http.EasyResponse;
import com.chenyuan.http.ReadInterfaceFromXml;
import org.testng.annotations.*;

import java.io.File;


/**
 * @ClassName: test2
 * @Author: 陈元
 * @Description:
 * @CreateDate: 2024/7/21 15:57
 * @Version: 1.0
 * @E-mail:1765065492@qq.com
 * @Link:https://github.com/1765065492
 */
//@Listeners(CustomReportListener.class)
public class test2 {
    String environmentName;
    /**
     * 定义所有接口信息所在文件夹
     */
    //
    protected final File INTER_INFO_FOLDER = new File("src/main/resources/com/chenyuan/info/");

    /**
     * 定义百度接口信息文件
     */
    protected final File BAIDU_INTER_INFO = new File(INTER_INFO_FOLDER, "testcase.xml");
    /**
     * 接口信息读取类对象
     */
    protected static ReadInterfaceFromXml xml;
    /**
     * 接口请求工具
     */
    protected static EasyHttp request;
    /**
     * 存储接口响应内容
     */
    private EasyResponse response;

    /**
     * 该方法用于初始化执行容器
     */
    @BeforeSuite(alwaysRun = true)
    public void initVessel() {
        request = new EasyHttp();
        // 设置断言失败时抛出异常
        //request.isAssertFailThrowException(true);
        // 添加需要的公式
        System.out.println();

        request.addFunction(Functions.randomString());
    }

    /**
     * 该方法用于初始化接口自动化执行前前置
     */
    @BeforeClass(alwaysRun = true)
    public void initRead() {
        xml = new ReadInterfaceFromXml(BAIDU_INTER_INFO);
    }

    /**
     * 该方法用于对每个执行步骤执行后，进行接口后置处理（此处简单写为展示响应报文）
     */
    @AfterMethod
    public void showResponse() {
        System.out.println("响应状态码：" + response.getStatus());
        System.out.println("响应消息：" + response.getMessage());
        System.out.println("响应头：" + response.getResponseHeaderMap());
        System.out.println("响应体：" + response.getResponseBodyText());

    }

    /**
     * 该方法用于执行test_01_02的步骤1
     */
    @Test(invocationCount = 3)
    public void test_01_02_step_01() {
        response = request.requst(xml.getInterface("搜索接口","环境1"));
    }

    /**
     * 该方法用于执行Test_01_02的步骤1
     */
/*    @Test
    public void test_01_02_step_01() {
        response = request.requst(xml.getInterface("日志名称接口"));
        logId = request.getReplaceKey("logId");
        System.out.println("提取到的logId为：" + logId);
    }*/

    @Test
    public void test_01_02_step_03() {
        response = request.requst(xml.getInterface("新增用户接口","环境1"));
    }

    /*
    * 测试后台shouted是否可以访问
    * */
    @Test
    public void test_01_02_step_04() {
        response = request.requst(xml.getInterface("后台首页","环境1"));
    }


    /*
    * 获取验证码
    * */
    @Test
    public void test_01_02_step_05() {
        //assertResultSet
        response = request.requst(xml.getInterface("获取管理员列表","环境1"));
/*        Set<String> assertResult = request.getAssertResult();
        for (String result : assertResult) {
            // 这里可以对每个 result 进行处理
            System.out.println(result+"断言结果"); // 举例输出
        }*/
    }

    @Test
    public void test_01_02_step_06() {
        response = request.requst(xml.getInterface("添加管理人员","环境1"));
    }

    @Test
    public void test_01_02_step_07() {

        response = request.requst(xml.getInterface("添加管理人员2","环境1"));
    }





}
